//
//  SearchView.m
//  ProjectsOne
//
//  Created by iOS开发 on 2018/7/11.
//  Copyright © 2018年 iOS开发. All rights reserved.
//

#import "SearchView.h"

@implementation SearchView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    CGFloat SearchWidth = 305 * (WIDTH / 375);
    UIView *bgView = [[UIView alloc] init];
    bgView.layer.cornerRadius = 14;
    [self addSubview:bgView];
    bgView.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(self);
        make.height.mas_equalTo(28);
        make.width.mas_equalTo(SearchWidth);
    }];
    
    UIImage *searchImage = [UIImage imageNamed:@"search_magnifier"];
    UIImageView *searchImageView = [[UIImageView alloc] initWithImage:searchImage];
    [bgView addSubview:searchImageView];
    [searchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView).offset(10);
        make.centerY.equalTo(bgView);
        make.width.height.mas_equalTo(15);
    }];
    
    self.searchFiled = [[UITextField alloc] init];
    [bgView addSubview:_searchFiled];
    [_searchFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(searchImageView.mas_right).offset(7);
        make.top.bottom.right.equalTo(bgView);
    }];
    _searchFiled.returnKeyType = UIReturnKeySearch;
    _searchFiled.font = [UIFont systemFontOfSize:15];
    _searchFiled.textColor = [UIColor colorWithHexString:@"333333"];
    _searchFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
    _searchFiled.inputAccessoryView = [UIView new];
    
    NSString *holderText = @"请输入关键字";
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
    [placeholder addAttribute:NSForegroundColorAttributeName
                        value:[UIColor colorWithHexString:@"a8a8a8"]
                        range:NSMakeRange(0, holderText.length)];
    [placeholder addAttribute:NSFontAttributeName
                        value:[UIFont boldSystemFontOfSize:15]
                        range:NSMakeRange(0, holderText.length)];
    _searchFiled.attributedPlaceholder = placeholder;
    
}

- (CGSize)intrinsicContentSize {
    return UILayoutFittingExpandedSize;
}

@end
